package yxy.game.pm2.active.command.goldfristpay;

import com.alibaba.fastjson.JSONObject;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_元宝首冲;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActGoldFristPayInfoRequest;

@MessageType(proto = Command.ActGoldFristPayInfo, classtype = ActiveMessage.ActGoldFristPayInfoRequest.class)
public class CMD_Active_元宝首冲_Info extends Command<ActGoldFristPayInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, ActGoldFristPayInfoRequest request) throws Exception {
		String pcode = messageSource.getTag();
		ActiveMessage.ActGoldFristPayInfoResponse.Builder response = ActiveMessage.ActGoldFristPayInfoResponse.newBuilder();
		
		ActiveModule_元宝首冲 am = ActiveModule_元宝首冲.get(pcode);
		if(am == null) {
			response.setFirstpayinfo("{}");
			send(messageSource, response, Result.DataError);
			return;
		}
		
		JSONObject json = am.firstpayinfo();
		response.setFirstpayinfo(json.toString());
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ActiveMessage.ActGoldFristPayInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
